package com.mryan.auth.service.impl;

import com.mryan.auth.dao.AccountDao;
import com.mryan.auth.pojo.Account;
import com.mryan.auth.pojo.Message;
import com.mryan.auth.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description： LoginServiceImpl
 * @Author MRyan
 * @Date 2021/6/14 16:54
 * @Version 1.0
 */
@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private AccountDao accountDao;

    @Override
    public Message checkPassword(String accountName, String accountPassword) {
        Account account = accountDao.getAccountInfoByName(accountName);
        if (null == accountPassword)
            return new Message(201, "登录失败", new Account());
        if (null == account)
            return new Message(202, "登录失败", new Account());
        if (!accountPassword.equals(account.getAccountPassword()))
            return new Message(203, "登录失败", new Account());
        return new Message(200, "登录成功", account);
    }

    @Override
    public Message getAccountInfo(Long accountId) {
        Account accountInfoById = accountDao.getAccountInfoById(accountId);
        if (null == accountInfoById)
            return new Message(201, "获取用户信息失败", new Account());
        Account account = new Account();
        account.setAccountId(accountInfoById.getAccountId());
        account.setAccountAvatar(accountInfoById.getAccountAvatar());
        account.setAccountName(accountInfoById.getAccountName());
        account.setAccountPhone(accountInfoById.getAccountPhone());
        return new Message(200, "获取用户信息成功", account);
    }
}
